home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58606
/
58606.xpi
/
chrome
/
translator.jar
/
content
/
translatorLoader.js
< prev
next >
Wrap
Text File
|
2010-02-07
|
3KB
|
93 lines
// declaring jQuery variable
var translatorJQuery = jQuery.noConflict(true);
// initializing package namespace
if(!com) var com = {};
if(!com.igorgladkov) com.igorgladkov = {};
if(!com.igorgladkov.translator) com.igorgladkov.translator = {};
(function(namespace, $)
{
namespace.TranslatorLoader = function()
{
// empty costructor
};
namespace.TranslatorLoader.prototype = {
translator: null,
ui: null,
prefs: null,
properties: null,
load: function()
{
var appcontent = document.getElementById('appcontent');
if(!appcontent) return;
if(!appcontent.translator) {
appcontent.translator = true;
// start prefs manager
this.prefs = new namespace.PrefsManager();
// get properties
this.properties = $('#translator-properties').get(0);
// create translator ui
this.ui = new namespace.TranslatorUI();
// create translator
this.translator = new namespace.Translator(this.prefs, this.ui);
this.translator.init();
appcontent.addEventListener('DOMContentLoaded', this.pageLoadedHandler.bind(this), false);
}
this.checkUpdateStatus();
},
checkUpdateStatus: function(e)
{
// get installed version
var extensionManager = Components.classes['@mozilla.org/extensions/manager;1'].getService(Components.interfaces.nsIExtensionManager);
var installedVersion = extensionManager.getItemForID('{5C655500-E712-41e7-9349-CE462F844B19}').version;
// get saved version from preferences (null if add-on was just installed)
var savedVersion = this.prefs.getPref('_version') || -1;
// if extension was updated
if(installedVersion != savedVersion) {
this.prefs.setPref('_version', installedVersion, 32/*string*/);
// load webpage if translator was installed for the first time or updated
window.setTimeout(function() {
gBrowser.selectedTab = gBrowser.addTab('http://igorgladkov.com/extensions/translator.html');
}, 1000);
}
},
pageLoadedHandler: function(e)
{
// initialize new page
var page = new namespace.Page(this.translator, this.properties);
page.init(e.originalTarget);
}
};
// load event listener
$(window).one('load.translator', function() {
var translatorLoader = new namespace.TranslatorLoader();
translatorLoader.load();
}, false);
// binding function
Function.prototype.bind = function(o) {
var m = this;
return function() {
return m.apply(o, arguments);
};
}
})(com.igorgladkov.translator, translatorJQuery);